home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / utilities / system / intuition / shadow / examples / swri / control.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-17  |  9.1 KB  |  337 lines

  1. /*
  2.  * SWRI controller Program.
  3.  *
  4.  * © Copyright 1991, ALl Rights Reserved
  5.  *
  6.  * David C. Navas
  7.  */
  8. #include <shadow/semaphore.h>
  9. #include "control.h"
  10. #include "/Gui/gui.h"
  11.  
  12. #include <ipc.h>
  13. #include <shadow/shadow_proto.h>
  14. #include <shadow/shadow_pragmas.h>
  15. #include <dos/dostags.h>
  16.  
  17. extern struct ExecBase * __far SysBase;
  18. struct IPCBase * __far IPCBase;
  19. struct ShadowBase * __far ShadowBase;
  20. struct DosLibrary * __far DOSBase;
  21.  
  22. /*
  23.  * external class definitions.
  24.  */
  25. char GuiProcClassName[] = GUIPROCESSCLASS,
  26.      GuiTaskName[] = GUITASK,
  27.      GuiClassName[] = GUICLASS,
  28.      WindowClassName[] = WINDOWCLASS,
  29.      GadgTClassName[] = GADGTCLASS;
  30.  
  31.  
  32. struct Task * __far programTask;
  33.  
  34. #define WINNAME "SWRINDE CONTROL PANEL"
  35.  
  36. /*
  37.  * This is the data class that I will use.  Don't need to
  38.  *  actually create a class like this, unless I want it automatically
  39.  *  created by the cluster below.
  40.  */
  41.  
  42. ATTRIBUTE_TAG dataAttrs[] =
  43.                         {
  44.                            {
  45.                               ATTR_SWRINDE_DATA, sizeof(double) * 256, NULL
  46.                            },
  47.                            TAG_END
  48.                         };
  49.  
  50.  
  51. /*
  52.  * This is the Cluster that I will create.
  53.  *
  54.  * It creates one instance of the above class.
  55.  */
  56.  
  57. void blankMethod(METHOD_ARGS);
  58.  
  59. METHOD_TAG clusterMethods[] =
  60.                         {
  61.                            {
  62.                               METHOD_SWRINDECONTROLCLUSTER_COMPUTE,
  63.                               NULL, NULL,
  64.                               SHADOW_MSG_CALL,
  65.                               METHOD_FLAG_PROC, 0,
  66.                               (METHODFUNCTYPE)blankMethod, NULL
  67.                            },
  68.                            TAG_END
  69.                         };
  70.  
  71. /*
  72.  * My local window.
  73.  */
  74.  
  75. void CWinRemoveMethod(METHOD_ARGS);
  76.  
  77. BOOL CWinInitMethod(METHOD_ARGS);
  78.  
  79. METHOD_TAG CWinMethods[] =
  80.                         {
  81.                            {
  82.                               METHOD_META_INIT,
  83.                               NULL, NULL,
  84.                               SHADOW_MSG_SYNC,
  85.                               METHOD_FLAG_PROC, 0,
  86.                               (METHODFUNCTYPE)CWinInitMethod, NULL
  87.                            },
  88.                            {
  89.                               METHOD_META_REMOVE,
  90.                               NULL, NULL,
  91.                               SHADOW_MSG_SYNC,
  92.                               METHOD_FLAG_PROC, 0,
  93.                               (METHODFUNCTYPE)CWinRemoveMethod, NULL
  94.                            },
  95.                            TAG_END
  96.                         };
  97.  
  98. struct SignalSemaphore programSemaphore;
  99.  
  100. int CXBRK(void)
  101. {
  102.    return(0);
  103. }
  104.  
  105. chkabort(void)
  106. {
  107.    return(0);
  108. }
  109.  
  110. void loadControl(void);
  111.  
  112. void main(void)
  113. {
  114.    CLASS  procClass;
  115.    OBJECT procObject = NULL;
  116.  
  117.    InitSemaphore(&programSemaphore);
  118.    programTask = FindTask(NULL);
  119.  
  120.    if (DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))
  121.    {
  122.       if (IPCBase = OpenLibrary("ppipc.library", 0))
  123.       {
  124.          if (ShadowBase = (struct ShadowBase *)
  125.                            OpenLibrary("shadow.library", 4))
  126.          {
  127.             PSem(NULL, SHADOW_EXCLUSIVE_SEMAPHORE);
  128.             if ((procClass = FindJazzClass(PROCESSCLASS)) &&
  129.                 !(procObject = FindStringInWatchedBinTree(
  130.                                (W_AVLTREE)
  131.                                 FindAttribute(procClass, ATTR_OBJECTLIST),
  132.                                SWRINDE_CONTROL_PROGRAM)))
  133.             {
  134.                DropObject(procClass);
  135.                if (InitOOProgram(SWRINDE_CONTROL_PROGRAM))
  136.                {
  137.                   VSem(NULL);
  138.                   loadControl();
  139.  
  140.                   RemoveCurrentProgram(&programSemaphore);
  141.                } else
  142.                {
  143.                   VPrintf("Coult not init your program\n", NULL);
  144.                   VSem(NULL);
  145.                }
  146.  
  147.             } else
  148.             {
  149.                VSem(NULL);
  150.                VPrintf("Hey -- your program is already running, no need to run it again!\n", NULL);
  151.                DropObject(procObject);
  152.                DropObject(procClass);
  153.             }
  154.  
  155.             CloseLibrary(ShadowBase);
  156.          }
  157.          else
  158.             VPrintf("requires shadow.library V4.3 in libs:\n", NULL);
  159.  
  160.          CloseLibrary(IPCBase);
  161.       }
  162.       else
  163.          VPrintf("requires ppipc.library in libs:\n", NULL);
  164.    }
  165.    else
  166.    {
  167.       DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0);
  168.       Write(Output(), "Sorry, use 2.0\n", 15);
  169.    }
  170.    CloseLibrary(DOSBase);
  171. }
  172.  
  173. void loadControl(void)
  174. {
  175.    CLASS       table[2];
  176.    OBJECT      guiTask;
  177.    W_AVLTREE   wbt;
  178.    BOOL        success;
  179.  
  180.    if (InitGUISystem())
  181.    {
  182.       /*
  183.        * Find the guiTask.
  184.        */
  185.  
  186.       if (wbt = FindAttribute(programTask->tc_UserData, ATTR_RESOURCETREE))
  187.          guiTask = FindStringInWatchedBinTree(wbt, GUITASK);
  188.       else
  189.          guiTask = NULL;
  190.  
  191.       SetupMethodTags(CWinMethods, guiTask, (void *)-1);
  192.       SetupMethodTags(clusterMethods, (void *)-1, (void *)-1);
  193.       DropObject(guiTask);
  194.  
  195.       /*
  196.        * Create my own Window Class
  197.        */
  198.       success = AddAutoResource(NULL,
  199.                                 CreateSubClass(NULL,
  200.                                                WINDOWCLASS,
  201.                                                METACLASS,
  202.                                                CONTROLWINCLASS,
  203.                                                NULL,
  204.                                                NULL,
  205.                                                CWinMethods,
  206.                                                METHOD_END),
  207.                                 CONTROLWINCLASS);
  208.  
  209.       /*
  210.        * Create the window.
  211.        */
  212.       success &= (BOOL)CreateInstance(NULL,
  213.                                       CONTROLWINCLASS,
  214.                                       METACLASS,
  215.                                       METHOD_END);
  216.  
  217.  
  218.       /*
  219.        * Create the data class.
  220.        */
  221.       table[0] = CreateSubClass(NULL,
  222.                                 ROOTCLASS,
  223.                                 METACLASS,
  224.                                 SWRINDE_DATA_CLASS,
  225.                                 NULL,
  226.                                 dataAttrs,
  227.                                 METHOD_END);
  228.  
  229.       /*
  230.        * Now create the data cluster
  231.        */
  232.       table[1] = NULL;
  233.       success &= AddAutoResource(NULL,
  234.                                  CreateSubClass(NULL,
  235.                                                 ROOTCLUSTER,
  236.                                                 METACLUSTER,
  237.                                                 SWRINDE_CONTROL_CLUSTER,
  238.                                                 NULL,
  239.                                                 NULL,
  240.                                                 clusterMethods,
  241.                                                 table,
  242.                                                 METHOD_END),
  243.                                  SWRINDE_CONTROL_CLUSTER);
  244.  
  245.       /*
  246.        * Transfer ownership to the programTask.
  247.        */
  248.       success &= AddAutoResource(NULL, table[0], SWRINDE_DATA_CLASS);
  249.  
  250.       if (success)
  251.          HandleMessages(programTask);
  252.    }
  253. }
  254.  
  255. /*
  256.  * CWin Class methods.
  257.  */
  258.  
  259. BOOL CWinInitMethod(METHOD_ARGS)
  260. {
  261.    struct TagItem tag[10];
  262.  
  263.    tag[0].ti_Tag = WA_Width;
  264.    tag[0].ti_Data = 150;
  265.    tag[1].ti_Tag = WA_Height;
  266.    tag[1].ti_Data = 100;
  267.    tag[2].ti_Tag = WA_MinWidth;
  268.    tag[2].ti_Data = 60;
  269.    tag[3].ti_Tag = WA_MinHeight;
  270.    tag[3].ti_Data = 40;
  271.    tag[4].ti_Tag = WA_MaxWidth;
  272.    tag[4].ti_Data = -1;
  273.    tag[5].ti_Tag = WA_MaxHeight;
  274.    tag[5].ti_Data = -1;
  275.    tag[6].ti_Tag = WA_SimpleRefresh;
  276.    tag[6].ti_Data = TRUE;
  277.    tag[7].ti_Tag = WA_Left;
  278.    tag[7].ti_Data = 0;
  279.    tag[8].ti_Tag = WA_Top;
  280.    tag[8].ti_Data = 0;
  281.    tag[9].ti_Tag = TAG_END;
  282.  
  283.    object = DoJazzMethod(object, class->meta_superClass, METHOD_META_INIT,
  284.                                               NULL,
  285.                                               WINNAME,
  286.                                               NULL,
  287.                                               NULL,
  288.                                               tag, METHOD_END);
  289.    if (!object)
  290.       return FALSE;
  291.  
  292.  
  293.  
  294.    /*
  295.     * Okay, we have a window.  Now we need the close gadget.
  296.     */
  297.    {
  298.       struct NewGadget  ng;
  299.  
  300.       ng.ng_LeftEdge = 15;
  301.       ng.ng_TopEdge = 45;
  302.       ng.ng_Width = 80;
  303.       ng.ng_Height = 20;
  304.       ng.ng_Flags = 0;
  305.       DropObject(CreateInstance(NULL,
  306.                                 GADGTCLASS,
  307.                                 METACLASS,
  308.                                 object,
  309.                                 "QUIT",
  310.                                 object,
  311.                                 METHOD_META_REMOVE,
  312.                                 &ng,
  313.                                 BUTTON_KIND,
  314.                                 METHOD_END));
  315.    }
  316.  
  317.    /*
  318.     * Get rid of this object FIRST!  Probably not important, but better
  319.     *  not take any chances, add it priority one.
  320.     */
  321.    return AddAutoResource(programTask->tc_UserData, object, (char *)1);
  322. }
  323.  
  324. void CWinRemoveMethod(METHOD_ARGS)
  325. {
  326.  
  327.    Signal(programTask, SIGBREAKF_CTRL_C);
  328.    CallSuper();               /* Let GadTools know to get rid of gadgets. */
  329. }
  330.  
  331. /*
  332.  * Blank method that is patched by all the other modules.
  333.  */
  334. void blankMethod(METHOD_ARGS)
  335. {
  336.    return;
  337. }